cmake_minimum_required(VERSION 3.16)

project(generate_qt_shared_library LANGUAGES CXX)

set(CMAKE_INSTALL_PREFIX "D:/mydata/mylib/${CMAKE_PROJECT_NAME}/" CACHE PATH "安装目录" FORCE)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

add_library(generate_qt_shared_library SHARED
  generate_qt_shared_library_global.h
  generate_qt_shared_library.cpp
  generate_qt_shared_library.h
)

target_link_libraries(generate_qt_shared_library PRIVATE Qt${QT_VERSION_MAJOR}::Core)

target_compile_definitions(generate_qt_shared_library PRIVATE GENERATE_QT_SHARED_LIBRARY_LIBRARY)

# 安装共享库
install(TARGETS generate_qt_shared_library
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib
        RUNTIME DESTINATION bin)

# 安装头文件
install(FILES
        generate_qt_shared_library_global.h
        generate_qt_shared_library.h
        DESTINATION include)

# 安装源文件
install(FILES
        generate_qt_shared_library.cpp
        DESTINATION src)